/*
 * Copyright 2010, Andrew M Gibson
 *
 * www.andygibson.net
 *
 * This file is part of DataValve.
 *
 * DataValve is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DataValve is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with DataValve.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fluttercode.datavalve.params;

import java.util.Collection;

/**
 * A value holder used to store resolved parameters.
 *
 * @author Andy Gibson
 */
public final class Parameter {

    /** 参数名 */
    private String name;
    /** 参数值 */
    private Object value;

    public Parameter() {
    }

    public Parameter(String name) {
        this.name = name;
    }

    public Parameter(String name, Object value) {
        this.name = name;
        this.value = value;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Object getValue() {
        return value;
    }

    public void setValue(Object value) {
        this.value = value;
    }

    public boolean isNull() {
        if (value == null) {
            // 空对象NULL
            return true;
        } else if (value instanceof String && ((String) value).length() == 0) {
            // 0长度字符串
            return true;
        } else if (value instanceof Collection && ((Collection) value).isEmpty()) {
            // 空集合
            return true;
        } else if (value instanceof Object[] && ((Object[]) value).length == 0) {
            // 0长度数组
            return true;
        } else {
            return false;
        }
    }

    public boolean isNotNull() {
        return !isNull();
    }

    @Override
    public String toString() {
        return "Parameter{" + "name=" + name + ", value=" + value + '}';
    }
}
